var e, t = require("./@babel/runtime/helpers/interopRequireDefault"), r = t(require("./@babel/runtime/regenerator")), a = t(require("./@babel/runtime/helpers/asyncToGenerator")), l = require("./scope"), n = require("./mock"), s = wx.getSystemInfoSync(), i = s.windowWidth, o = s.windowHeight, c = i - 20, h = [];

Page({
    data: {
        mode: 3,
        title: "告白小人制作",
        sentence: "告白小人制作",
        rowNum: 1,
        canvasWidthG: c,
        littlePeopleList: n.initLittlePeople,
        toggle: !1,
        isLongScreen: Boolean(o > 800)
    },
    onLoad: function(t) {
        e = wx.createCanvasContext("myCanvas"), this.drawLittlePeople3();
    },
    inputValue: function() {
        var e = (0, a.default)(r.default.mark(function e(t) {
            var a, n, s;
            return r.default.wrap(function(e) {
                for (;;) switch (e.prev = e.next) {
                  case 0:
                    return a = t.detail.value, e.next = 3;

                  case 3:
                    if (n = e.sent, s = this.data.mode, !n) {
                        e.next = 28;
                        break;
                    }
                    this.setData({
                        sentence: a,
                        rowNum: Math.ceil(a.length / 6)
                    }), e.t0 = s, e.next = 1 === e.t0 ? 10 : 2 === e.t0 ? 12 : 3 === e.t0 ? 14 : 4 === e.t0 ? 16 : 5 === e.t0 ? 18 : 6 === e.t0 ? 20 : 7 === e.t0 ? 22 : 8 === e.t0 ? 24 : 26;
                    break;

                  case 10:
                    return this.drawLittlePeople1(), e.abrupt("break", 28);

                  case 12:
                    return this.drawLittlePeople2(), e.abrupt("break", 28);

                  case 14:
                    return this.drawLittlePeople3(), e.abrupt("break", 28);

                  case 16:
                    return this.drawLittlePeople4(), e.abrupt("break", 28);

                  case 18:
                    return this.drawLittlePeople5(), e.abrupt("break", 28);

                  case 20:
                    return this.drawLittlePeople6(), e.abrupt("break", 28);

                  case 22:
                    return this.drawLittlePeople7(), e.abrupt("break", 28);

                  case 24:
                    return this.drawLittlePeople8(), e.abrupt("break", 28);

                  case 26:
                    return console.log("without mode."), e.abrupt("break", 28);

                  case 28:
                  case "end":
                    return e.stop();
                }
            }, e, this);
        }));
        return function(t) {
            return e.apply(this, arguments);
        };
    }(),
    changePersonStyle: function(e) {
        var t = e.currentTarget.dataset.index;
        switch (this.setData({
            mode: t
        }), t) {
          case 1:
            this.drawLittlePeople1();
            break;

          case 2:
            this.drawLittlePeople2();
            break;

          case 3:
            this.drawLittlePeople3();
            break;

          case 4:
            this.drawLittlePeople4();
            break;

          case 5:
            this.drawLittlePeople5();
            break;

          case 6:
            this.drawLittlePeople6();
            break;

          case 7:
            this.drawLittlePeople7();
            break;

          case 8:
            this.drawLittlePeople8();
            break;

          default:
            this.drawLittlePeople3();
        }
    },
    drawLittlePeople1: function() {
        var t = this.data, r = t.sentence, a = t.rowNum, l = 0;
        l = r.length <= 6 ? c - 375 < 0 ? 5 + c * (6 - r.length) / 12 : (c - 375) / 2 + 5 + 375 * (6 - r.length) / 12 : c - 375 < 0 ? 5 : (c - 375) / 2 + 5;
        var n = (c - 80 * a) / 2 > 0 ? (c - 80 * a) / 2 : 0;
        e.setFillStyle("white"), e.fillRect(0, 0, c, c), e.draw();
        for (var s = 0; s < a; s++) for (var i = 0; i < 6; i++) if (r[6 * s + i]) {
            var o = l + 55 * i - 10, h = n + 80 * s;
            e.drawImage("./imgs/littleperson/1/".concat(this.getNumber(), ".png"), o, h, 80, 80), 
            e.setTextAlign("center"), e.font = "sans-serif bold 18px cursive", e.setFillStyle("black"), 
            e.fillText(r[6 * s + i], o + 40, h + 63), e.draw(!0);
        }
    },
    drawLittlePeople2: function() {
        var t, r, a = this.data, l = a.sentence, n = a.rowNum, s = c;
        e.setFillStyle("white"), e.fillRect(0, 0, c, c), e.draw();
        for (var i = 0; i < n; i++) for (var o = 0; o < 6; o++) l[6 * i + o] && (l.length <= 6 ? (t = s / 6 - 40 + n * s / 24 - i * s / 12 + 5 + s * (6 - l.length) / 18 + s * o / 9, 
        r = s / 3 - 50 - n * s / 12 + i * s / 7 + 50 + s * (6 - l.length) / 36 + s * o / 18) : (t = s / 6 - 40 + n * s / 24 - i * s / 12 + 5 + s * o / 9, 
        r = s / 3 - 50 - n * s / 12 + i * s / 7 + 50 + s * o / 18), e.drawImage("./imgs/littleperson/2/1.png", t, r, 80, 100), 
        e.setTextAlign("center"), e.font = "sans-serif bold 14px cursive", e.save(), e.setFillStyle("black"), 
        e.translate(t + 33, r + 20), e.rotate(20 * Math.PI / 180), e.transform(1, 0, -.6, 1, 0, 0), 
        e.fillText(l[6 * i + o], 0, 0), e.restore(), e.draw(!0));
    },
    drawLittlePeople3: function() {
        var t, r, a = this.data, l = a.sentence, n = a.rowNum, s = c;
        e.setFillStyle("white"), e.fillRect(0, 0, c, c), e.draw();
        for (var i = 0; i < n; i++) for (var o = 0; o < 6; o++) l[6 * i + o] && (l.length <= 6 ? (t = s / 6 - 35 + n * s / 24 - i * s / 12 + 5 + s * (6 - l.length) / 18 + s * o / 9, 
        r = s / 3 - 50 - n * s / 12 + i * s / 7 + 50 + s * (6 - l.length) / 36 + s * o / 18) : (t = s / 6 - 35 + n * s / 24 - i * s / 12 + 5 + s * o / 9, 
        r = s / 3 - 50 - n * s / 12 + i * s / 7 + 50 + s * o / 18), e.drawImage("./imgs/littleperson/3/".concat(this.getNumber(), ".png"), t, r, 70, 100), 
        e.setFillStyle("black"), e.setTextAlign("center"), e.font = "sans-serif bold 14px cursive", 
        e.save(), e.translate(t + 29, r + 18), e.transform(1, 0, -.1, 1, 0, 0), e.rotate(20 * Math.PI / 180), 
        e.transform(1, 0, -.5, 1, 0, 0), e.fillText(l[6 * i + o], 0, 0), e.restore(), e.draw(!0));
    },
    drawLittlePeople4: function() {
        var t, r, a = this.data, l = a.sentence, n = a.rowNum, s = c;
        e.setFillStyle("white"), e.fillRect(0, 0, c, c), e.draw();
        for (var i = 0; i < n; i++) for (var o = 0; o < 6; o++) l[6 * i + o] && (l.length <= 6 ? (t = s / 6 - 30 + n * s / 24 - i * s / 12 + 5 + s * (6 - l.length) / 18 + s * o / 9, 
        r = s / 3 - 35 - n * s / 12 + i * s / 7 + 50 + s * (6 - l.length) / 36 + s * o / 18) : (t = s / 6 - 30 + n * s / 24 - i * s / 12 + 5 + s * o / 9, 
        r = s / 3 - 35 - n * s / 12 + i * s / 7 + 50 + s * o / 18), e.drawImage("./imgs/littleperson/4/".concat(this.getNumber(), ".png"), t, r, 60, 70), 
        e.setTextAlign("center"), e.font = "sans-serif bold 14px cursive", e.save(), e.translate(t + 25, r + 17), 
        e.rotate(14 * Math.PI / 180), e.transform(1, 0, -.8, 1, 0, 0), e.setFillStyle("black"), 
        e.fillText(l[6 * i + o], 0, 0), e.restore(), e.draw(!0));
    },
    drawLittlePeople5: function() {
        var t, r, a = this.data, l = a.sentence, n = a.rowNum, s = c;
        e.setFillStyle("white"), e.fillRect(0, 0, c, c), e.draw();
        for (var i = 0; i < n; i++) for (var o = 0; o < 6; o++) l[6 * i + o] && (l.length <= 6 ? (t = s / 6 - 25 + n * s / 24 - i * s / 12 + 5 + s * (6 - l.length) / 18 + s * o / 9, 
        r = s / 3 - 50 - n * s / 12 + i * s / 7 + 50 + s * (6 - l.length) / 36 + s * o / 18) : (t = s / 6 - 25 + n * s / 24 - i * s / 12 + 5 + s * o / 9, 
        r = s / 3 - 50 - n * s / 12 + i * s / 7 + 50 + s * o / 18), e.drawImage("./imgs/littleperson/5/".concat(this.getNumber(), ".png"), t, r, 50, 100), 
        e.setTextAlign("center"), e.font = "sans-serif bold 16px cursive", e.save(), e.translate(t + 21, r + 19), 
        e.rotate(24 * Math.PI / 180), e.transform(1, 0, -.59, 1, 0, 0), e.setFillStyle("black"), 
        e.fillText(l[6 * i + o], 0, 0), e.restore(), e.draw(!0));
    },
    drawLittlePeople6: function() {
        var t, r = this.data, a = r.sentence, l = r.rowNum;
        t = a.length <= 6 ? c - 375 < 0 ? 5 + c * (6 - a.length) / 12 : (c - 375) / 2 + 5 + 375 * (6 - a.length) / 12 : c - 375 < 0 ? 5 : (c - 375) / 2 + 5;
        var n = (c - 80 * l) / 2 > 0 ? (c - 80 * l) / 2 : 0;
        e.setFillStyle("white"), e.fillRect(0, 0, c, c), e.draw();
        for (var s = 0; s < l; s++) for (var i = 0; i < 6; i++) if (a[6 * s + i]) {
            var o = t + 55 * i - 10, h = n + 80 * s;
            e.drawImage("./imgs/littleperson/6/".concat(this.getNumber(), ".png"), o, h, 80, 80), 
            e.setTextAlign("center"), e.font = "sans-serif bold 18px cursive", e.setFillStyle("black"), 
            e.fillText(a[6 * s + i], o + 40, h + 61), e.draw(!0);
        }
    },
    drawLittlePeople7: function() {
        var t, r, a = this.data, l = a.sentence, n = a.rowNum, s = c;
        e.setFillStyle("white"), e.fillRect(0, 0, c, c), e.draw();
        for (var i = 0; i < n; i++) for (var o = 0; o < 6; o++) l[6 * i + o] && (l.length <= 6 ? (t = s / 6 - 40 + n * s / 24 - i * s / 12 + 5 + s * (6 - l.length) / 18 + s * o / 9, 
        r = s / 3 - 50 - n * s / 12 + i * s / 7 + 50 + s * (6 - l.length) / 36 + s * o / 18) : (t = s / 6 - 40 + n * s / 24 - i * s / 12 + 5 + s * o / 9, 
        r = s / 3 - 50 - n * s / 12 + i * s / 7 + 50 + s * o / 18), e.setFillStyle("black"), 
        e.drawImage("./imgs/littleperson/7/".concat(this.getNumber(), ".png"), t, r, 80, 100), 
        e.setTextAlign("center"), e.font = "sans-serif bold 14px cursive", e.save(), e.translate(t + 26, r + 16), 
        e.rotate(22 * Math.PI / 180), e.transform(1, 0, -.89, 1, 0, 0), e.fillText(l[6 * i + o], 0, 0), 
        e.restore(), e.draw(!0));
    },
    drawLittlePeople8: function() {
        var t, r = this.data, a = r.sentence, l = r.rowNum;
        t = a.length <= 6 ? c - 375 < 0 ? 15 + c * (6 - a.length) / 12 : (c - 375) / 2 + 15 + 375 * (6 - a.length) / 12 : c - 375 < 0 ? 15 : (c - 375) / 2 + 15;
        var n = (c - 70 * l) / 2 > 0 ? (c - 70 * l) / 2 : 0;
        e.setFillStyle("white"), e.fillRect(0, 0, c, c), e.draw();
        for (var s = 0; s < l; s++) for (var i = 0; i < 6; i++) if (a[6 * s + i]) {
            var o = t + 55 * i - 10, h = n + 70 * s;
            e.setFillStyle("black"), e.drawImage("./imgs/littleperson/8/".concat(this.getNumber(), ".png"), o, h, 60, 70), 
            e.setTextAlign("center"), e.font = "sans-serif bold 16px cursive", e.fillText(a[6 * s + i], o + 40, h + 25), 
            e.draw(!0);
        }
    },
    savePic: function() {
        var e = (0, a.default)(r.default.mark(function e() {
            var t, a;
            return r.default.wrap(function(e) {
                for (;;) switch (e.prev = e.next) {
                  case 0:
                    return e.next = 2, (0, l.checkHasImageSaveScope)();

                  case 2:
                    if (!e.sent) {
                        e.next = 18;
                        break;
                    }
                    return e.prev = 4, e.next = 7, wx.promisify(wx.canvasToTempFilePath)({
                        canvasId: "myCanvas"
                    });

                  case 7:
                    return t = e.sent, a = t.tempFilePath, e.next = 11, wx.promisify(wx.saveImageToPhotosAlbum)({
                        filePath: a
                    });

                  case 11:
                    wx.showToast({
                        title: "图片保存成功"
                    }), e.next = 18;
                    break;

                  case 14:
                    e.prev = 14, e.t0 = e.catch(4), console.log({
                        e: e.t0
                    }), wx.showToast({
                        title: "图片保存失败",
                        icon: "none"
                    });

                  case 18:
                  case "end":
                    return e.stop();
                }
            }, e, null, [ [ 4, 14 ] ]);
        }));
        return function() {
            return e.apply(this, arguments);
        };
    }(),
    showBox: function() {
        this.setData({
            toggle: !this.data.toggle
        });
    },
    hideBox: function() {
        this.setData({
            toggle: !1
        });
    },
    getNumber: function() {
        return 0 === h.length && (h = (0, l.shuffle)([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ])), 
        h.shift();
    },
    onShareAppMessage: function() {}
});